import React, { Component } from "react";

export default class ArrowFnCom extends Component {
  //声明状态
  state = {
    count: 100,
  };

  //1. 添加方法时, 通过箭头函数赋值的形式, 向实例对象添加成员
  add = () => {
    this.setState({
      count: this.state.count + 1,
    });
  }

  render() {
    return (
      <div>
        <h2>{this.state.count}</h2>
        {/*2. 使用 this.add 设置事件回调 */}
        <button onClick={this.add}>新增</button>
        <button
          onClick={() => {
            this.setState({
              count: this.state.count - 1,
            });
          }}
        >
          减少
        </button>
      </div>
    );
  }
}
